const std = @import("std");
const Point = @import("point.zig");
const Hull = @import("geometry/hull.zig");
const Gjk = @import("geometry/gjk.zig");
const Common = @import("geometry/common.zig");

test {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    var map_prng = std.Random.DefaultPrng.init(@intCast(std.time.timestamp()));
    const map_rand = map_prng.random();

    var proxy: Gjk.Proxy = undefined;
    {
        var list = std.ArrayList(Point).init(allocator);
        defer list.deinit();

        for (0..128) |_| {
            try list.append(Point.init(map_rand.float(f32) * 500, map_rand.float(f32) * 500));
        }

        std.debug.print("{d}\n", .{@intFromPtr(list.items.ptr)});

        proxy = Gjk.Proxy.init(list.items, 0);
        std.debug.print("{d}\n", .{@intFromPtr(proxy.vertices.ptr)});
        std.debug.print("{d} {d}\n", list.items[0]);

        const t = Common.MassData.init(1, Point.init(2, 3), 3);
        std.debug.print("{d}\n", .{@intFromPtr(&t)});

        std.debug.print("{d} {d}\n", .{ @sizeOf([3]u16), @alignOf([3]u16) });
        std.debug.print("{d} {d}\n", .{ @sizeOf(*Point), @alignOf(Gjk.SupportPointInfo) });
    }
}

fn b2InvMulRot(r1: Point.Rotation, r2: Point.Rotation) Point.Rotation {
    return Point.Rotation{
        .cosine = r1.cosine * r2.cosine + r1.sine * r2.sine,
        .sine = r1.cosine * r2.sine - r1.sine * r2.cosine,
    };
}

test "point" {
    var point1 = Point.init(5, 5);
    var point2 = Point.init(5, 5);
    const self_tx = Point.Transform.init(Point.init(1, 5), std.math.pi / 6.0);
    const other_tx = Point.Transform.init(Point.init(1, 5), std.math.pi / 3.0);

    point1.transform2OtherLocal(&self_tx, &other_tx);
    std.debug.print("{d} {d}\n", point1);

    point2.transform(&self_tx.ifInverseMul(&other_tx));
    std.debug.print("{d} {d}\n", point2);
}
